package cronjob

import (
	"go-zero-admin/pkg/result"
	"net/http"

	"github.com/zeromicro/go-zero/rest/httpx"
	"go-zero-admin/application/job/api/internal/logic/cronjob"
	"go-zero-admin/application/job/api/internal/svc"
	"go-zero-admin/application/job/api/internal/types"
)

// 重启定时任务
func ReloadCronHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.ReloadCronReq
		if err := httpx.Parse(r, &req); err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
			return
		}

		l := cronjob.NewReloadCronLogic(r.Context(), svcCtx)
		resp, err := l.ReloadCron(&req)
		result.HttpResult(r, w, resp, err)
	}
}
